package gui.swing;

import javax.swing.*;
import java.awt.*;
import java.net.URL;

public class OnlyChoose extends JFrame {

    public OnlyChoose(){
        Container contentPane = this.getContentPane();
        //将一个图片变为图标
        String url = "E:\\new PC\\study\\java学习\\code\\JavaSE\\基础语法\\src\\gui\\swing\\zsh.jpg";

        Icon icon = new ImageIcon(url);

        //单选框
        JRadioButton btn1 = new JRadioButton("btn1");
        JRadioButton btn2 = new JRadioButton("btn2");
        JRadioButton btn3 = new JRadioButton("btn3");

        //单选框只能选一个，则要分组
        ButtonGroup buttonGroup = new ButtonGroup();
        buttonGroup.add(btn1);
        buttonGroup.add(btn2);
        buttonGroup.add(btn3);


        contentPane.add(btn1,BorderLayout.CENTER);
        contentPane.add(btn2,BorderLayout.SOUTH);
        contentPane.add(btn3,BorderLayout.NORTH);

        this.setVisible(true);
        this.setBounds(100,100,200,200);
        setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
    }

    public static void main(String[] args) {
        new OnlyChoose();
    }
}
